/*
* PureMVC Logger v1.0
* Copyright (c) 2009 We Are Cloud.
* Author: Yannick Chaze
*
* Based on PureMVC code
* See http://puremvc.org for more informations
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0.
*
* PureMVC MultiCore - Copyright(c) 2006-08 Futurescale, Inc., Some rights reserved.
* Your reuse is governed by the Creative Commons Attribution 3.0 United States License
*/

package com.wearecloud.puremvclogger.patterns.observer
{
	import com.wearecloud.puremvclogger.core.ControllerLogger;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.interfaces.IObserver;

	/**
	 * This class is equivalent to the PureMVC 
	 * <code>Observer</code> class but change
	 * accessibility of the context to public
	 */
	
	public class ObserverLogger implements IObserver
	{
		private var notify:Function;
		private var context:Object;
	
		/**
		 * @inheritDoc
		 */
		public function ObserverLogger( notifyMethod:Function, notifyContext:Object ) 
		{
			setNotifyMethod( notifyMethod );
			setNotifyContext( notifyContext );
		}
		
		/**
		 * @inheritDoc
		 */
		public function setNotifyMethod( notifyMethod:Function ):void
		{
			notify = notifyMethod;
		}
		
		/**
		 * @inheritDoc
		 */
		public function setNotifyContext( notifyContext:Object ):void
		{
			context = notifyContext;
		}
		
		/**
		 * @inheritDoc
		 */
		private function getNotifyMethod():Function
		{
			return notify;
		}
		
		/**
		 * @inheritDoc
		 */
		public function getNotifyContext():Object
		{
			return context;
		}
		
		/**
		 * @inheritDoc
		 */
		public function notifyObserver( notification:INotification ):void
		{
			this.getNotifyMethod().apply(this.getNotifyContext(),[notification]);
		}
	
		/**
		 * @inheritDoc
		 */
		 public function compareNotifyContext( object:Object ):Boolean
		 {
		 	return object === this.context;
		 }		
	}
}